Home /

Developer Resource Kit 5 Article

Weather Sample Application

The Weather sample application uses the XML Connector component that comes with Macromedia Flash MX Professional 2004 to connect to a weather web service. The only code in the application is in the form of event listeners, error-checking functions, styles, local shared objects, and favorites.

Weather sample application example

Figure 1. Weather sample application example

The current feature set includes the following weather features:

  • Current location
  • Current temperature
  • Current forecast
  • Current wind conditions
  • Five-day highs
  • Five-day lows
  • Five-day forecast

Additional features include:

  • Add favorites
  • Remove favorites
  • Auto-save settings (using local shared objects)

Installing Weather

To install the Weather sample application, simply extract the SWF to your hard drive and open the file.

If you want to run this application on a website, you need to create a proxy. You can find more information about creating a proxy in this Flash TechNote: "Loading Data Across Domains."

Learning from Weather

The Weather sample application shows just how easy it is to use the new XML Connector component:

  1. Drag the XML Connector component onto the Stage.
  2. Give it an instance name of connector.
  3. Click the the Parameters tab in the Component inspector and enter the following URL in the space provided: http://www.ejse.com/WeatherService/Service.asmx/GetExtendedWeatherInfo?zipCode=10001
    Set the Direction value as receive.
  4. Drag a TextInput component onto the Stage. Give it an instance name of zipcode_txt.
  5. Drag a Button component onto the Stage. Give it an instance name of submit_btn.
  6. Put the following code in the Actions layer of your movie:

    submit_btn.addEventListener("click", getWeather);
    
    function getWeather(){
        connector.URL = "http://www.ejse.com/WeatherService/Service.asmx/GetExtendedWeatherInfo?zipCode=" + zipcode_txt.text
        connector.trigger();
    }
    
  7. In a web browser go to the following URL: http://www.ejse.com/WeatherService/Service.asmx/GetExtendedWeatherInfo?zipCode=10001
    Save the XML file to your hard drive as example.xml.
  8. Select the XML Connector component on the Stage and click the Schema tab in the Component inspector. Select the Results property, click the Import button on the right side (the icon with the downward pointing arrow), and browse to the example.xml file you just saved and open it.
  9. Drag three Label components onto the Stage. Name them label1, label2, and label3, respectively.
  10. Select the XML Connector component again and click the Bindings tab in the Component inspector.
  11. Click the plus (+) symbol to open the Add Binding dialog box. Browse to the Info:Object > Location:String value and click OK.
  12. With the Bindings tab selected, set the Direction value as out. For the Bound To value, click the magnifying glass and select the label1 instance.
  13. Repeat Steps 10–12 and bind the Temperature and Forecast values.
  14. Test your movie by entering a ZIP code and clicking Submit. It's as easy as that.

Note: It might take a minute for the web service to return data. The selected web service is a little slow sometimes.